package ystp.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ystp.dao.*;
import ystp.model.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class FujianbJieguoService {

    @Resource
    FujianbJieguoMapper ddMapper;
    @Autowired
    FujianbMapper fujianbMapper;
    public List<Map<String, Object>> findPinzhong(String ppxiangmuId,String ppDrugname,
                                                  int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findPinzhong(ppxiangmuId,ppDrugname,mmStartIndex,ppPageSize);
    }
    public List<Map<String, Object>> findPinguiByPinzhong(String ppxiangmuId,String mmPinzhongOne,String ppuserId){
        return ddMapper.findPinguiByPinzhong(ppxiangmuId,mmPinzhongOne,ppuserId);
    }
    public List<Map<String, Object>> findYouxiaoyitou(String ppxiangmuId,String ppuserId){
        return ddMapper.findYouxiaoyitou(ppxiangmuId,ppuserId);
    }
    public List<Map<String, Object>> findPinguiFenlei(String ppxiangmuId,String mmPinzhongOne){
        return ddMapper.findPinguiFenlei(ppxiangmuId,mmPinzhongOne);
    }
    public Integer getPinguiCount(String ppxiangmuId,int ppPageIndex, int ppPageSize) {
        Object mmCount = ddMapper.getPinguiCount(ppxiangmuId,ppPageIndex,ppPageSize);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }
    public FujianbJieguo checkexistByUserId(String ppPinguixuhao, String ppUserId, String ppxiangmuid){
        FujianbJieguoExample mmExample=new FujianbJieguoExample();
        mmExample.createCriteria().andPinguiEqualTo(ppPinguixuhao).andUseridEqualTo(ppUserId).andXiangmuidEqualTo(ppxiangmuid);
        return ddMapper.selectByExample(mmExample).size()>0? ddMapper.selectByExample(mmExample).get(0): null;
    }
    public Integer piaoshu(String ppPinzhongxuhao, String ppPinguixuhao, String ppxiangmuid){
        FujianbJieguoExample mmExample=new FujianbJieguoExample();
        mmExample.createCriteria().andPinzhongEqualTo(ppPinzhongxuhao).andPinguiEqualTo(ppPinguixuhao).andXiangmuidEqualTo(ppxiangmuid).andResultEqualTo("1");
        Object mmCount=ddMapper.selectByExample(mmExample).size();
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }
    public Integer checkCountByPinzhongandUserId(String ppPinghzongxuhao, String ppUserId,String ppxiangmuid){
        FujianbJieguoExample mmExample=new FujianbJieguoExample();
        mmExample.createCriteria().andPinzhongEqualTo(ppPinghzongxuhao).andUseridEqualTo(ppUserId).andXiangmuidEqualTo(ppxiangmuid).andResultEqualTo("1");
        Object mmCount=ddMapper.selectByExample(mmExample).size();
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public Integer checkCountYouwugongxiao(String ppxiangmuid){
        FujianbExample mmExample=new FujianbExample();
        mmExample.createCriteria().andXiangmuidEqualTo(ppxiangmuid).andYouwutonggongxiaoEqualTo("有");
        Object mmCount=fujianbMapper.selectByExample(mmExample).size();
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }
    public boolean modify(FujianbJieguo ppFujianbJieguo){
        return ddMapper.updateByPrimaryKeySelective(ppFujianbJieguo)==1;
    }
    public boolean add(FujianbJieguo ppFujianbJieguo){
        return ddMapper.insert(ppFujianbJieguo)==1;
    }

    public int countPass(String ppXiangmuId,String ppUserId){

        Object  mmCount = ddMapper.countPass(ppXiangmuId,ppUserId);

        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }
    public int countPingui(String ppXiangmuId){

        Object  mmCount = ddMapper.countPingui(ppXiangmuId);

        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }


}
